class ClearCommentsWebpackPlugin {
  constructor(options = {}) {
    this.options = options
  }

  apply (compiler) {
    console.log('clear start')
    compiler.hooks.emit.tap('ClearCommentsWebpackPlugin', compilation => {
      for (const name in compilation.assets) {
        if (name.endsWith('.js')) {
          const contents = compilation.assets[name].source()
          const clearComments = contents.replace(/\/\*\*+\*\//g, '')
          compilation.assets[name] = {
            source: () => clearComments, // 插件必须写的参数
            size: () => clearComments.length, // 插件必须写的参数
          }
        }
      }
    })
  }
}

module.exports = ClearCommentsWebpackPlugin